<?php

namespace iBrand\Component\Goods\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Spec extends Model
{
	use SoftDeletes;

	protected $guarded = ['id'];

	public function __construct(array $attributes = [])
	{
		parent::__construct($attributes);

		$prefix = config('ibrand.app.database.prefix', 'ibrand_');

		$this->setTable($prefix . 'base_spec');
	}

	public function getTypeNameAttribute()
	{
		return $this->attributes['type'] == 1 ? '文字' : '图片';
	}

	public function specValue()
	{
		return $this->hasMany(SpecsValue::class, 'spec_id');
	}
}